home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / ov-scalar.h < prev    next >
C/C++ Source or Header  |  1996-11-07  |  4KB  |  157 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_scalar_h)
  24. #define octave_scalar_h 1
  25.  
  26. #if defined (__GNUG__)
  27. #pragma interface
  28. #endif
  29.  
  30. #include <cstdlib>
  31.  
  32. #include <string>
  33.  
  34. class ostream;
  35.  
  36. #include "lo-utils.h"
  37. #include "mx-base.h"
  38. #include "oct-alloc.h"
  39. #include "str-vec.h"
  40.  
  41. #include "mappers.h"
  42. #include "ov-base.h"
  43. #include "ov-typeinfo.h"
  44.  
  45. class Octave_map;
  46. class octave_value_list;
  47.  
  48. class tree_walker;
  49.  
  50. // Real scalar values.
  51.  
  52. class
  53. octave_scalar : public octave_base_value
  54. {
  55. public:
  56.  
  57.   octave_scalar (void)
  58.     : octave_base_value (), scalar (0.0) { }
  59.  
  60.   octave_scalar (double d)
  61.     : octave_base_value (), scalar (d) { }
  62.  
  63.   octave_scalar (const octave_scalar& s)
  64.     : octave_base_value (), scalar (s.scalar) { }
  65.  
  66.   ~octave_scalar (void) { }
  67.  
  68.   octave_value *clone (void) { return new octave_scalar (*this); }
  69.  
  70.   void *operator new (size_t size)
  71.     { return allocator.alloc (size); }
  72.  
  73.   void operator delete (void *p, size_t size)
  74.     { allocator.free (p, size); }
  75.  
  76.   octave_value index (const octave_value_list& idx) const;
  77.  
  78.   idx_vector index_vector (void) const { return idx_vector (scalar); }
  79.  
  80.   int rows (void) const { return 1; }
  81.   int columns (void) const { return 1; }
  82.  
  83.   bool is_defined (void) const { return true; }
  84.   bool is_real_scalar (void) const { return true; }
  85.  
  86.   octave_value all (void) const { return (scalar != 0.0); }
  87.   octave_value any (void) const { return (scalar != 0.0); }
  88.  
  89.   bool is_real_type (void) const { return true; }
  90.   bool is_scalar_type (void) const { return true; }
  91.   bool is_numeric_type (void) const { return true; }
  92.  
  93.   bool valid_as_scalar_index (void) const
  94.     { return (! xisnan (scalar) && NINT (scalar) == 1); }
  95.  
  96.   bool valid_as_zero_index (void) const
  97.     { return (! xisnan (scalar) && NINT (scalar) == 0); }
  98.  
  99.   bool is_true (void) const { return (scalar != 0.0); }
  100.  
  101.   double double_value (bool = false) const { return scalar; }
  102.  
  103.   Matrix matrix_value (bool = false) const { return Matrix (1, 1, scalar); }
  104.  
  105.   Complex complex_value (bool = false) const { return scalar; }
  106.  
  107.   ComplexMatrix complex_matrix_value (bool = false) const
  108.     { return  ComplexMatrix (1, 1, Complex (scalar)); }
  109.  
  110.   octave_value not (void) const { return octave_value (! scalar); }
  111.  
  112.   octave_value uminus (void) const { return octave_value (- scalar); }
  113.  
  114.   octave_value transpose (void) const { return octave_value (scalar); }
  115.  
  116.   octave_value hermitian (void) const { return octave_value (scalar); }
  117.  
  118.   void increment (void) { ++scalar; }
  119.  
  120.   void decrement (void) { --scalar; }
  121.  
  122.   octave_value convert_to_str (void) const;
  123.  
  124.   void print (ostream& os, bool pr_as_read_syntax = false);
  125.  
  126.   int type_id (void) const { return t_id; }
  127.  
  128.   string type_name (void) const { return t_name; }
  129.  
  130.   static int static_type_id (void) { return t_id; }
  131.  
  132.   static void register_type (void)
  133.     { t_id = octave_value_typeinfo::register_type (t_name); }
  134.  
  135. private:
  136.  
  137.   // The value of this scalar.
  138.   double scalar;
  139.  
  140.   // For custom memory management.
  141.   static octave_allocator allocator;
  142.  
  143.   // Type id of scalar objects, set by register_type().
  144.   static int t_id;
  145.  
  146.   // Type name of scalar objects, defined in ov-scalar.cc.
  147.   static const string t_name;
  148. };
  149.  
  150. #endif
  151.  
  152. /*
  153. ;;; Local Variables: ***
  154. ;;; mode: C++ ***
  155. ;;; End: ***
  156. */
  157.